package a2022.a20220613;

import java.util.Arrays;

/**
 * @author lenovo
 * @date 2022/6/13
 */
public class a {
    public static void main(String[] args) {
        int[] heights = {5,1,2,3,4};
        int i = heightChecker(heights);
        System.out.println(i);
    }
    public static int heightChecker(int[] heights) {
        int left = 0;
        int right = heights.length - 1;
        int[] expected = Arrays.copyOf(heights,heights.length);
        int num = 0;
        Arrays.sort(expected);
        while (left < right){
            if (heights[left] != expected[left]) num+=1;
            if (heights[right] != expected[right]) num+=1;
            left++;
            right--;
        }
        if (left==right) if (heights[left] != expected[left])num+=1;
        return num;
    }
}
